function FLogSaveBuilding () {
    var server = top.FLogGetServer ();
    var facility = server.GetBuilding (window.userloc, "facility");
    
    facility["sector"] = POgetSector ();
    var coords = POgetCoords ();
    facility["coords"] = coords;
    facility["player_owned"] = "false";
    
    var ths = document.getElementsByTagName ("th");
    for (var i=0; i<ths.length; i++) {
        var th = ths[i];
        if (th.textContent != "Owned by") continue;
        facility["owner"] = th.parentNode.nextSibling.cells[1].firstChild.textContent;
        try {
            var a = th.parentNode.nextSibling.cells[1];
            var b = a.getElementsByTagName ("font")[0];
            facility["owner_alliance"] = b.textContent;
        } catch (e){
            facility["owner_alliance"] = "";
        }
        try {
            var img = th.parentNode.nextSibling.cells[0].getElementsByTagName ("img")[0];
            var src = img.getAttribute("src").split("/");
            src = src[src.length-1].split("_")[1];
            if (src == 'fed') {
                facility["faction"] = "Federation";
            } else if (src == "uni") {
                facility["faction"] = "Union";
            } else if (src == "emp") {
                facility["faction"] = "Empire";
            }
        } catch (e){
            facility["faction"] = "Neutral";
        }
        facility["player_owned"] = "true";
    }

    var b = document.getElementsByTagName("b")[0];
    if (b) {
        facility["building_type"] = b.textContent;
        var html = b.parentNode.innerHTML;
        facility["building_condition"] = html.split("Condition: ")[1].split("%")[0];
        if (html.indexOf("building_trade.php") != -1) {
            facility["trade_open"] = "true";
        } else {
            facility["trade_open"] = "false";
        }
    }
    
    server.SaveFacility (window.userloc, facility, "facility");
}


FLogSaveBuilding ();